# Maintainer: Jaroslav Lichtblau <svetlemodry@archlinux.org>
# Contributor: flu

pkgname=sqlcipher
pkgver=4.5.2
pkgrel=2
pkgdesc="SQLite extension that provides transparent 256-bit AES encryption of database files"
arch=('loong64' 'x86_64')
url="https://www.zetetic.net/sqlcipher/"
license=('BSD')
depends=('openssl' 'sqlite' 'tcl' 'readline' 'zlib')
source=(https://www.zetetic.net/$pkgname/verify/$pkgver/$pkgname-$pkgver.zip{,.sig})
validpgpkeys=('D83F5F9EB811D6E6B4A0D9C5D1FA3A2A97ED25C2') # Zetetic LLC <support@zetetic.net>
sha256sums=('0a6549e2907733c9c8a98899fd4e77726e4d72ee43fc50bfcd31d2f311594deb'
            'SKIP')

build() {
  cd "${srcdir}"/$pkgname-$pkgver

  export CPPFLAGS="$CPPFLAGS \
    -DSQLITE_ENABLE_COLUMN_METADATA=1 \
    -DSQLITE_ENABLE_UNLOCK_NOTIFY \
    -DSQLITE_ENABLE_DBSTAT_VTAB=1 \
    -DSQLITE_ENABLE_FTS3_TOKENIZER=1 \
    -DSQLITE_SECURE_DELETE \
    -DSQLITE_ENABLE_STMTVTAB \
    -DSQLITE_MAX_VARIABLE_NUMBER=250000 \
    -DSQLITE_MAX_EXPR_DEPTH=10000 \
    -DSQLITE_ENABLE_MATH_FUNCTIONS"

  export CFLAGS="$CFLAGS -DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2 -DSQLCIPHER_TEST"
  export LDFLAGS="$LDFLAGS -lcrypto"

  ./configure --prefix=/usr \
    --enable-tempstore=yes \
    --disable-static \
    --enable-fts3 \
    --enable-fts4 \
    --enable-fts5 \
    --enable-rtree \
    --enable-json1
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
  make testfixture
}

check() {
  cd "${srcdir}"/$pkgname-$pkgver
  ./testfixture test/sqlcipher.test
}

package() {
  cd "${srcdir}"/$pkgname-$pkgver

  make DESTDIR="${pkgdir}" install

  #license
  install -Dm644 LICENSE "${pkgdir}"/usr/share/licenses/$pkgname/LICENSE
}
